package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.server.mapper.UserInfoMapper;
import com.tanhua.server.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserInfoService {

    @Autowired
    //注入用户信息的mapper对象
    private UserInfoMapper userInfoMapper;

    /**
     * 通过用户id进行用户信息的查询
     * @param userId
     * @return
     */
    public UserInfo queryUserInfoByUserId(Long userId) {
        //1.通过QueryWrapper进行匹配用户id进行查询
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);

        //2.返回查询到的用户信息
        return this.userInfoMapper.selectOne(queryWrapper);
    }

    /**
     * 查询用户集合信息
     * @param queryWrapper
     * @return
     */
    public List<UserInfo> queryUserInfoList(QueryWrapper<UserInfo> queryWrapper) {
        return this.userInfoMapper.selectList(queryWrapper);
    }

    /**
     * 更新用户信息
     * @param userInfo
     * @return
     */
    public Boolean updateUserInfoByUserId(UserInfo userInfo) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("user_id",userInfo.getUserId());
        return this.userInfoMapper.update(userInfo,queryWrapper) > 0;
    }
}
